const express = require('express')
const c = require('../connection')
const router = express.Router()
//  登录接口
router.post('/', (req, res) => {
    var obj = req.body
    c.query(`select * from uc_user where username=? and password=?`, [obj.username, obj.password], (err, r) => {
        if (err) {
            throw err
        }
        if (r.length != 0) {
            res.send({
                code: 200,
                msg: '登录成功',
                data: r
            })
        } else {
            res.send({
                code: 401,
                msg: '查询失败',
                data: r
            })
        }
    })
})
//注册账号
router.post('/register', (req, res) => {
    var obj = req.body
    c.query(`insert into uc_user set ?`, [obj], (err, r) => {
        if (err) {
            throw err
        }
        res.send({
            code: 200,
            msg: '注册成功',
            data: r
        })
    })
})
module.exports = router